package com.example.myFirstWebmagic.dailyAirReport.processor;

import com.example.myFirstWebmagic.pipeline.ConsolePipelineDemo;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.processor.PageProcessor;

public class NewAirDailyStarttimeProcessor implements PageProcessor{

	
	
	// 部分一：抓取网站的相关配置，包括编码、抓取间隔、重试次数等
    private Site site = Site.me().setRetryTimes(10).setSleepTime(5000);
    
    //页面上的开始时间
    private String startime="";
    
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String [] startUrl=new String[]{"http://datacenter.mep.gov.cn/index!getCityMain.action"};
		// TODO Auto-generated method stub
		NewAirDailyStarttimeProcessor process= new NewAirDailyStarttimeProcessor();
		Spider spider =Spider.create(process);
        //从"http://datacenter.mep.gov.cn/index!getCityMain.action"开始抓
		spider.addUrl(startUrl)
        .addPipeline(new ConsolePipelineDemo())
        //开启5个线程抓取
        .thread(5)
        //启动爬虫
        .run();
		
		System.out.println(process.getStartime());
	}

	public void process(Page page){
		// TODO Auto-generated method stub
		//获取开始时间
		setStartime(page.getHtml().xpath("//input[@id='start']/@value").toString());
		
	}

	public Site getSite() {
		// TODO Auto-generated method stub
		return site;
	}

	public String getStartime() {
		return startime;
	}

	public void setStartime(String startime) {
		this.startime = startime;
	}

}
